package com.ruoyi.web.controller.seed;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SeedApply;
import com.ruoyi.system.service.ISeedApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 种子申请Controller
 *
 * @author ruoyi
 * @date 2021-07-08
 */
@RestController
@RequestMapping("/seed/apply")
public class SeedApplyController extends BaseController
{
    @Autowired
    private ISeedApplyService seedApplyService;

    /**
     * 查询种子申请列表
     */
    @PreAuthorize("@ss.hasPermi('seed:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(SeedApply seedApply)
    {
        startPage();
        List<SeedApply> list = seedApplyService.selectSeedApplyList(seedApply);
        return getDataTable(list);
    }

    /**
     * 导出种子申请列表
     */
    @PreAuthorize("@ss.hasPermi('seed:apply:export')")
    @Log(title = "种子申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SeedApply seedApply)
    {
        List<SeedApply> list = seedApplyService.selectSeedApplyList(seedApply);
        ExcelUtil<SeedApply> util = new ExcelUtil<SeedApply>(SeedApply.class);
        return util.exportExcel(list, "种子申请数据");
    }

    /**
     * 获取种子申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('seed:apply:query')")
    @GetMapping(value = "/{seedApplyId}")
    public AjaxResult getInfo(@PathVariable("seedApplyId") Long seedApplyId)
    {
        return AjaxResult.success(seedApplyService.selectSeedApplyById(seedApplyId));
    }

    /**
     * 新增种子申请
     */
    @PreAuthorize("@ss.hasPermi('seed:apply:add')")
    @Log(title = "种子申请", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody SeedApply seedApply)
    {
        return toAjax(seedApplyService.insertSeedApply(seedApply));
    }

    /**
     * 修改种子申请
     */
    @PreAuthorize("@ss.hasPermi('seed:apply:edit')")
    @Log(title = "种子申请", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody SeedApply seedApply)
    {
        return toAjax(seedApplyService.updateSeedApply(seedApply));
    }

    /**
     * 删除种子申请
     */
    @PreAuthorize("@ss.hasPermi('seed:apply:remove')")
    @Log(title = "种子申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{seedApplyIds}")
    public AjaxResult remove(@PathVariable Long[] seedApplyIds)
    {
        return toAjax(seedApplyService.deleteSeedApplyByIds(seedApplyIds));
    }
}
